﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class CentersA : System.Web.UI.Page
{
    protected string sTitle = string.Empty;
    protected ArticleItem article;
    protected CategoryItem catItem;
    protected CategoryItem DiagItem;

    protected void Page_Load(object sender, EventArgs e)
    {
        GetParameters();

        HtmlMeta meta = new HtmlMeta();
        meta.Name = "keywords";
        meta.Content = PageHeaderData.GetArticleKeywords((int)article.articleId);
        this.Header.Controls.Add(meta);
        // metadata description
        meta = new HtmlMeta();
        meta.Name = "description";
        meta.Content = article.articleFragment;
        this.Header.Controls.Add(meta);

        catItem = Category.ItemById(article.catId);
        sTitle = catItem.cTitle;


        Page.Title = article.BrowserTitle;
        // Hightlight main menu
        ucHeader1.index = "4";

        // hide date
        if (!article.isDateVisible)
            divDate.Visible = false;

        // Get news by theme
        Dal.arParams.Clear();
        Dal.arParams.Add(catItem.catId);//CatID
        Dal.arParams.Add(article.articleId);//ArticleID
        DataTable DT = Dal.ExecuteDBsp("usp_GetNewsByCategory", Dal.arParams);
        if (DT != null)
            if (DT.Rows.Count > 0)
            {
                lblMoreNews.Visible = true;
                gvNews.DataSource = DT;
                gvNews.DataBind();
            }

        //Diagnostic
        DataTable DTDiag = Dal.ExecuteDBsp("usp_GetDiagnostic");
        if (DTDiag != null)
        {
            DiagItem = new CategoryItem();
            //DiagItem.cTitle = DTDiag.Rows[0]["title"].ToString();
            //DiagItem.cPageName = DTDiag.Rows[0]["cPageName"].ToString();

            string sOutput=string.Empty;
            for (int iCount = 1; iCount < DTDiag.Rows.Count; iCount++)
            {
                DataRow DR = DTDiag.Rows[iCount];
                sOutput += string.Format("<div class=\"centerbut2\">" +
                                        "<a href='{1}.aspx'>{0}</a></div>",
                                        DR["title"], DR["cpageName"]);
            }
            ulDiags.InnerHtml += sOutput;
        }
    }

    private void GetParameters()
    {
        string sFilename = Request.Params["a"];

        article = Articles.GetArticleByName(sFilename);
    }
}
